package com.lnu_devteam.zongce.utils;

import com.lnu_devteam.zongce.exception.BusinessException;
import com.lnu_devteam.zongce.func.BranchHandle;
import com.lnu_devteam.zongce.func.ThrowExceptionFunction;

/**
 * @author xbaozi
 * @version 1.0
 * @classname FuncUtils
 * @date 2023-02-02  19:20
 * @description 接口函数工具类
 */
public class FuncUtils {
    /**
     * @description 利用消费型接口抛异常
     * @author xbaozi
     * @date 2023/2/2 19:38
     **/
    public static ThrowExceptionFunction isTrueToThr(boolean flag) {
        return errorCode -> {
            if (flag) {
                throw new BusinessException(errorCode);
            }
        };
    }

    /**
     * @description 分支逻辑处理
     * @author xbaozi
     * @date 2023/2/9 21:09
     **/
    public static BranchHandle isTureOrFalse(boolean flag){

        return (trueHandle, falseHandle) -> {
            if (flag){
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    }
}
